# login_md5
# 2024/10/20
# author:www
'''
请求数据类型：post(
content-type中可查看是什么类型
data:表单数据，
json：请求体是json格式
file: 文件上传接口
param: 参数在请求地址中
)
'''
import copy

'''
课堂知识：json不是python专有的类型
1、json格式中正确的赋值，键用双引号
2、json正确的赋值:{"name": null,"sex":true}
3、python正确的赋值:{"name": None,"sex":True}
'''
import hashlib


import requests

from configs.config import login_request # 从配置文件中导入变量

# http://phissvc.phccloud.com/system/auth/login/getToken
host = 'http://phissvc.phccloud.com/'
def __get_md5_data(psw: str):
    """
    函数内部注释叫做：__doc__属性
    :param psw: 字符串密码
    :return: 返回md5加密后的密码结果
    操作：鼠标放在函数名称上，会弹窗显示三引号中的内容
    """
    md5 = hashlib.md5()
    md5.update(psw.encode('utf-8'))
    return md5.hexdigest()
print(__get_md5_data.__doc__) # 打印三引号中的内容



def login(l_data):
    url =f'{host}/system/auth/login/getToken'
    print('请求地址:',url)
    l_data = copy.copy(l_data) # 浅拷贝
    # l_data["password"] = __get_md5_data(l_data["password"])
    l_data["password"] = "neuh75fdj5LV0SuGtKsDvg"   # 因为使用md5加密报错，所以直接赋值用来调试浅拷贝功能
    login_data = l_data
    print('请求内容:',login_data)
    rep = requests.post(url, json=login_data)
    print('请求头：',rep.headers)
    # 打印请求中的内容需要用rep.request
    print('请求体：', rep.request.body)
    # 设置响应编码：rep.encoding = unicode_escape
    if rep.status_code == 200:
        return rep.json()
    else:
        return rep.text




def get_high_blood_pressure(h_data,headers):
    url = f'{host}/phis/hyper/follow/getPage'
    rep = requests.post(url, json=h_data, headers=headers)
    return rep.json()


# neuh75fdj5LV0SuGtKsDvg
if __name__ == '__main__':
    # login_request = {"loginAccount": "nanxiongwujing_Admin", "password": "neuh75fdj5LV0SuGtKsDvg", "validCode": "9527",
    #              "validCodeKey": "1729163153805"}
    print('加密前', login_request)  # 传递的是从config文件中读取的内容：'password': 'neuh75fdj5LV0SuGtKsDvg'
    res = login(login_request) # 读取配置文件中的变量作为参数
    print('加密后', login_request) # 通过调用加密方法，修改了密码的值，因为改的还是原来的变量地址，
    # 所以会影响配置文件中的变量的内容：'password': 'dc0529c43fb343fd5e528646834ec498'
    # token_v = res['results']['accessToken']
    # uaaid_v = res['results']['userDTO']['id']
    # headers = {'Content-Type': 'application/json','Authorization': f'Bearer {token_v}','Uaaid':uaaid_v}
    # hbp_request = {"current":1,"pageSize":15,"condition":{"name":"","idNumber":"","visitDateList":[],"visitDateStart":"","visitDateEnd":"","orgId":"440282_040"}}
    # high_blood_pressure = get_high_blood_pressure(hbp_request,headers)
    # print(high_blood_pressure)


